package com.uniview.plugins.workplus;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import net.sf.json.JSONObject;
import poggyio.workplus.po.WorkplusToken;
import poggyio.workplus.service.WorkplusService;

/**
 * workplusAPI对接管理类
 * 
 * @author Qingtian Lei
 *
 */
@Service
public class WorkplusApiService {

	static Logger logger = Logger.getLogger(WorkplusApiService.class);

	@Value("#{configProperties['uniview.grant_type']}")
	private String grant_type; // token类型 (client_credentials | password)

	@Value("#{configProperties['uniview.scope']}")
	private String scope; // 适用类型 (app | user)

	@Value("#{configProperties['uniview.domain_id']}")
	private String domain_id; // 域标识

	@Value("#{configProperties['uniview.org_id']}")
	private String org_id; // 组织标识(组织编号)

	@Value("#{configProperties['uniview.client_id']}")
	private String client_id; // 应用key | 用户名

	@Value("#{configProperties['uniview.client_secret']}")
	private String client_secret; // 应用secret | 用户密码

	@Value("#{configProperties['uniview.device_id']}")
	private String device_id; // 设备Id

	@Value("#{configProperties['uniview.device_platform']}")
	private String device_platform; // 设备平台

	@Value("#{configProperties['uniview.workpuls_url']}")
	private String workpuls_url;

	@Value("#{configProperties['uniview.templateId']}")
	private String templateId;
	
	/**
	 * 根据账号获取雇员信息
	 * @param username
	 * @return
	 */
	public JSONObject getWorkplusEmployees(String username) {
		try {
			WorkplusToken workplusToken = WorkplusService.getAppToken(domain_id, org_id, client_id, client_secret);
			return WorkplusService.getWorkplusEmployeesWithUserName(this.workpuls_url, workplusToken, username);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
